#include "src/OpcListener.hpp"

class TestHandler
{
public:
	void handler(const UA_NodeId &nodeId, const UA_Variant &value)
	{
		std::cout << std::string((char*)nodeId.identifier.string.data, nodeId.identifier.string.length) << " value changed." << std::endl;
		if(value.type == &UA_TYPES[UA_TYPES_INT16])
		{
			std::cout << "New value: " << *(UA_Int16*)value.data << std::endl;
		}
		else
		{
			std::cout << "Error: Unknown type." << std::endl;
		}
	}
};

int main()
{
	OpcListener listener;

	listener.setIntervalMs(1000);
	listener.setReconnectParameters(1000, 5);
	listener.connect("opc.tcp://localhost:4840");

	TestHandler testHandler;

	listener.addListener(4, "test", &testHandler, &TestHandler::handler);

	while(listener.isRunning())
	{
		std::this_thread::sleep_for(std::chrono::seconds(1));
	}
	return 0;
}